﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Portal.Xml.Utility;

namespace Portal.Cms.Model
{
    public class StudentSurveyCls
    {
        public string StudentSurveyId;
        public string StudentCode = "";
        public string StudentName = "";
        public string TrainingLevel = "";
        public string TrainingSubject = "";
        public string UniversityName = "";
        public string Course = "";
        public string Class = "";
        public DateTime SurveyDate;
        public string StudentId = "";
        public string Dob = "";
        public int Sex = 0;
        public string FinishedYear;
        public string WorkingAddress;
        public string HomeAddress;
    }

    public class StudentSurveyParser
    {
        public static StudentSurveyCls CreateInstance()
        {
            //tao 1 class trang....
            StudentSurveyCls oStudentSurveyCls = new StudentSurveyCls();
            return oStudentSurveyCls;
        }

        public static StudentSurveyCls ParseFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            StudentSurveyCls oStudentSurveyCls = ParseFromDataRow(ds.Tables[0].Rows[0]);
            return oStudentSurveyCls;
        }


        public static StudentSurveyCls ParseFromDataRow(DataRow dr)
        {
            StudentSurveyCls oStudentSurveyCls = new StudentSurveyCls();
            oStudentSurveyCls.StudentSurveyId = XmlUtility.GetString(dr, "StudentSurveyId", true);
            oStudentSurveyCls.StudentCode = XmlUtility.GetString(dr, "StudentCode", true);
            oStudentSurveyCls.StudentName = XmlUtility.GetString(dr, "StudentName", true);
            oStudentSurveyCls.Course = XmlUtility.GetString(dr, "Course", true);
            oStudentSurveyCls.Class = XmlUtility.GetString(dr, "Class", true);
            oStudentSurveyCls.TrainingLevel = XmlUtility.GetString(dr, "TrainingLevel", true);
            oStudentSurveyCls.TrainingSubject = XmlUtility.GetString(dr, "TrainingSubject", true);
            oStudentSurveyCls.Dob = XmlUtility.GetString(dr, "Dob", true);
            oStudentSurveyCls.SurveyDate = XmlUtility.GetDate(dr, "SurveyDate", true);
            oStudentSurveyCls.StudentId = XmlUtility.GetString(dr, "StudentId", true);
            oStudentSurveyCls.UniversityName = XmlUtility.GetString(dr, "UniversityName", true);
            return oStudentSurveyCls;
        }

        public static StudentSurveyCls[] ParseFromDataTable(DataTable dtTable)
        {
            StudentSurveyCls[] StudentSurveys = new StudentSurveyCls[dtTable.Rows.Count];
            for (int iIndex = 0; iIndex < dtTable.Rows.Count; iIndex++)
            {
                StudentSurveys[iIndex] = ParseFromDataRow(dtTable.Rows[iIndex]);
            }

            return StudentSurveys;
        }

        public static StudentSurveyCls[] ParseMultiRecordFromXml(string XmlData)
        {
            DataSet ds = XmlUtility.GetDataSetFromXml(XmlData);
            if (ds.Tables.Count == 0)
            {
                return new StudentSurveyCls[0];
            }
            StudentSurveyCls[] StudentSurveys = new StudentSurveyCls[ds.Tables[0].Rows.Count];
            for (int iIndex = 0; iIndex < ds.Tables[0].Rows.Count; iIndex++)
            {
                StudentSurveys[iIndex] = ParseFromDataRow(ds.Tables[0].Rows[iIndex]);
            }
            return StudentSurveys;
        }
    }
}
